﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;

namespace Query2Object
{
    /// <summary>
    /// handle the Items node in the config file
    /// 获取Items节点里的Add项的列表
    /// </summary>
    [ConfigurationCollection(typeof(ConnectionItem),AddItemName="Add",ClearItemsName="Clear",CollectionType=ConfigurationElementCollectionType.AddRemoveClearMap,RemoveItemName="Remove")]
    public class Connectionlist:ConfigurationElementCollection
    {
        private static ConfigurationPropertyCollection s_properties;
        static Connectionlist()
        {
            s_properties = new ConfigurationPropertyCollection();
        }

        public ConnectionItem this[int index]
        {
            get { return (ConnectionItem)base.BaseGet(index); }
            set
            {
                if (base.BaseGet(index) != null)
                    base.BaseRemoveAt(index);
                base.BaseAdd(index, value);
            }
        }
        public new ConnectionItem this[string Name]
        {
            get
            {
                return (ConnectionItem)base.BaseGet(Name);
            }
        }
        protected override ConfigurationPropertyCollection Properties
        {
            get { return s_properties; }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return base.CollectionType;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ConnectionItem();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ConnectionItem)element).name;
        }
    }
}
